//
//  OMBody.m
//  RequestTest
//
//  Created by xntech on 13-8-19.
//  Copyright (c) 2013年 xntech. All rights reserved.
//

#import "OMBody.h"
#import "OMHTTPConstant.h"
@implementation OMBody
- (id)init
{
    self = [super init];
    if (self)
    {
        _params = [[NSMutableDictionary alloc] init];
    }
    return self;
}
- (void)addParam:(id)object forKey:(id)key
{
    [_params setObject:[object description] forKey:[key description]];
}
- (void)addIntParam:(int)value forKey:(id)key
{
    NSNumber  *valueNum = [NSNumber numberWithInt:value];
    [self addParam:valueNum forKey:key];
}
- (void)addLongParam:(long long)value forKey:(id)key
{
    NSNumber  *valueNum = [NSNumber numberWithLongLong:value];
    [self addParam:valueNum forKey:key];
}
- (void)addDoubleParam:(double)value forKey:(id)key
{
    NSNumber  *valueNum = [NSNumber numberWithDouble:value];
    [self addParam:valueNum forKey:key];
}
- (void)addBoolParam:(BOOL)value forKey:(id)key
{
    NSString  *valueStr = nil;
    if (value) {
        valueStr = OMTRUE;
    }else{
        valueStr = OMFALSE;
    }
    [self addParam:valueStr forKey:key];
}
- (void)addDateParam:(NSDate *)date forKey:(id)key
{
    NSTimeInterval interval = [date timeIntervalSince1970];
    interval = interval * 1000;
    [self addLongParam:interval forKey:key];
}
- (void)setParams:(NSDictionary *)dic
{
    [_params removeAllObjects];
    [self addParams:dic];
}
- (void)addParams:(NSDictionary *)dic
{
    [_params addEntriesFromDictionary:dic];
}
- (int)count
{
    return [_params count];
}
- (NSArray *)allKeys
{
    return [_params allKeys];
}
- (id)paramForyKey:(NSString *)key
{
    return [_params objectForKey:key];
}
- (void)setRequestParams:(OMRequestParam *)param forKey:(id)key
{
    [_params setObject:param forKey:[key description]];
}
- (void)dealloc
{
    [_params release];
    [super dealloc];
}
@end
